package com.antwork.common.web.filter;

import java.io.IOException;
import java.io.PrintStream;
import java.util.Enumeration;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class LoginFilter implements Filter {
	private static String loginURL = null;
	private static String CALL_TYPE = "call-type";
	private static String escape = null;

	public void init(FilterConfig filterConfig) throws ServletException {
		loginURL = filterConfig.getInitParameter("login");
		escape = filterConfig.getInitParameter("escape");
		System.out.println("Init LoginFilter ! URL = " + loginURL);
	}

	public void doFilter(ServletRequest request, ServletResponse response,
			FilterChain chain) throws IOException, ServletException {
		HttpServletRequest req = (HttpServletRequest) request;
		HttpSession session = req.getSession();
		Enumeration headerNames = req.getHeaderNames();
		String callType = null;
		if (headerNames != null) {
			while (headerNames.hasMoreElements()) {
				String name = (String) headerNames.nextElement();
				if (name.equals(CALL_TYPE)) {
					callType = req.getHeader(name);
				}
			}
		}
		System.out.println("=======> callType = " + callType);
		chain.doFilter(request, response);
	}

	public void destroy() {
	}
}